import time
import threading


def singing():
    print("singing当前执行的线程为：", threading.current_thread())
    for i in range(10):
        print("唱歌...", i)
        time.sleep(0.5)


def dancing():
    print("dancing当前执行的线程为：", threading.current_thread())
    for i in range(10):
        print("跳舞...", i)
        time.sleep(0.5)


if __name__ == '__main__':
    print("主线程：", threading.current_thread())
    t1 = threading.Thread(target=singing)
    # 将子线程设置为守护线程
    t1.daemon = True
    t1.start()

    # 不要线程start之后设置，否则RuntimeError: cannot set daemon status of active thread
    # t1.daemon = True

    # 将子线程设置为守护线程, 并启动
    t2 = threading.Thread(target=dancing, daemon=True)
    t2.start()

    time.sleep(2)
    print("主线程执行完毕，退出")
    exit(0)
    print("----------")

